{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "2400"
test("2400 (copy_memory)", tests)
terminate_this_custom_script


function tests
    before_each(@setup)

    it("should copy nothing", test1)
    it("should copy 1 byte", test2)
    it("should copy 2 bytes", test3)
    it("should copy 3 bytes", test4)
    it("should copy 4 bytes", test5)
    it("should copy 5 bytes", test6)
    it("should copy 6 bytes", test7)
    it("should copy 7 bytes", test8)
    it("should copy 8 bytes", test9)
    it("should copy overlapping memory", test10)
    
    return
    
    :setup
        0@ = 0x11223344
        1@ = 0x55667788
        2@ = 0x99AABBCC
        3@ = 0xDDEEFF00
    return
    
    function test1
        10@ = get_var_pointer 1@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 0

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x99AABBCC)
        assert_eq(3@, 0xDDEEFF00)
    end
    
    function test2
        10@ = get_var_pointer 1@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 1

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x99AABB88) // modified
        assert_eq(3@, 0xDDEEFF00)
    end
    
    function test3
        10@ = get_var_pointer 1@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 2

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x99AA7788) // modified
        assert_eq(3@, 0xDDEEFF00)
    end
    
    function test4
        10@ = get_var_pointer 1@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 3

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x99667788) // modified
        assert_eq(3@, 0xDDEEFF00)
    end
    
    function test5
        10@ = get_var_pointer 1@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 4

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x55667788) // modified
        assert_eq(3@, 0xDDEEFF00)
    end
    
    function test6
        10@ = get_var_pointer 0@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 5

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x11223344) // modified
        assert_eq(3@, 0xDDEEFF88) // modified
    end
    
    function test7
        10@ = get_var_pointer 0@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 6

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x11223344) // modified
        assert_eq(3@, 0xDDEE7788) // modified
    end
    
    function test8
        10@ = get_var_pointer 0@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 7

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x11223344) // modified
        assert_eq(3@, 0xDD667788) // modified
    end
    
    function test9
        10@ = get_var_pointer 0@
        11@ = get_var_pointer 2@
        
        copy_memory {src} 10@ {dest} 11@ {size} 8

        assert_eq(0@, 0x11223344)
        assert_eq(1@, 0x55667788)
        assert_eq(2@, 0x11223344) // modified
        assert_eq(3@, 0x55667788) // modified
    end
    
    function test10
        longString str = "the test string"
        int trg = get_var_pointer str
        int scr = trg + 4
        
        copy_memory {src} scr {dest} trg {size} 8

        assert_eqs(str, "test str string")
    end
end
